<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2021/3/20
 * Time: 16:05
 */

namespace common\models\Books;


use common\models\base\BaseModel;
use common\models\bookscate\Bookscate;

class Books extends BaseModel
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%books}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['image','books_cate_id', 'name','file','desc','author', 'heat_degree', 'advert',
                'read_num', 'book_status', 'words', 'collect'], 'required'],
            [['created_at', 'updated_at', 'sort'], 'integer'],
            [['name'], 'string', 'max' => 50],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'image' => '图片',
            'name' =>'书籍名称',
            'books_cate_id' =>'书籍分类id',
            'file' => '书籍文件',
            'desc' => '简介',
            'author' => '作者',
            'heat_degree' => '热度',
            'read_num' => '阅读量',
            'book_status' => '书籍状态',
            'words' => '字数',
            'collect' =>'收藏量',
            'advert' => '广告',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
            'sort' => '排序',
        ];
    }
    public function getBooksCate()
    {
        return $this ->hasOne(Bookscate::class,['id'=>'books_cate_id']);
    }
}